import javax.smartcardio.ATR;
import javax.smartcardio.Card;
import javax.smartcardio.CardChannel;
import javax.smartcardio.CardException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class cardDemo {
    //花色
    public static final String[] suits = {"♦","♣","♥","♠"};

    //创建牌
    public static List<card> buyDeck(){
        //创建52张牌的容量
        List<card> deck = new ArrayList<>();
        //循环赋值
        //1.牌数
        for (int i = 1; i <= 13; i++) {
            //2.花色
            //创建对象
            for (int j = 0;j < 4;j++){
                int rank = i;
                String suit = cardDemo.suits[j];
                card tem = new card(rank,suit);
                //赋值
                deck.add(tem);
            }
        }
        //返回值
        return deck;
    }

    //交换
    public static void swap(List<card> deck,int i,int index){
        //创建变量
        card tem = deck.get(i);
        //将i下标坐标的值设置为index下标的值
        deck.set(i,deck.get(index));
        //将tem赋值给index下标的值
        deck.set(index,tem);
    }
    //将牌的顺序打乱
    public static void shuffle(List<card> deck){
        //创建生成随机数的对象
        Random random = new Random();
        //循环
        for (int i = deck.size() - 1; i > 0 ; i--) {
            int index = random.nextInt(i);
            //交换
            swap(deck,i,index);
        }
    }

}
